package com.gjintel.business.proj.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.gjintel.business.proj.dao.IProfessorDao;
import com.gjintel.business.proj.model.BidderChange;
import com.gjintel.business.proj.model.ProfessorInfo;
import com.gjintel.sdk.base.dao.HibernateGenericDAO;
import com.gjintel.sdk.base.dao.Page;
import com.gjintel.sdk.util.StringUtil;

@Repository("professorDao")
@SuppressWarnings("unchecked")
public class ProfessorDaoImpl extends HibernateGenericDAO implements IProfessorDao {

	@Override
	public List<ProfessorInfo> getProfessorInfo(String projectId, Page page) {
		List<Object> paramList = new ArrayList<Object>();
		String hql = "from ProfessorInfo pi where pi.projId=?";
		paramList.add(projectId);
		return this.findAsPage(hql.toString(), page, paramList.toArray());
	}

	@Override
	public List<ProfessorInfo> getProfessorList(String projectId) {
		List<Object> paramList = new ArrayList<Object>();
		String hql = "from ProfessorInfo pi where pi.projId=?";
		paramList.add(projectId);
		return this.find(hql, paramList.toArray());
	}

	@Override
	public List<ProfessorInfo> getProfessorInfoList(ProfessorInfo professorInfo, Page page) {
		List<Object> paramList = new ArrayList<Object>();
		StringBuffer hql = new StringBuffer("from ProfessorInfo pi where 1=1 ");
		
		if(professorInfo!=null){
			if(!StringUtil.isEmpty(professorInfo.getProjId())){
				hql.append(" and pi.projId=?");
				paramList.add(professorInfo.getProjId());
			}
			if(!StringUtil.isEmpty(professorInfo.getType())){
				hql.append(" and pi.type=?");
				paramList.add(professorInfo.getType());
			}
		}
		
		return this.findAsPage(hql.toString(), page, paramList.toArray());
	}

	@Override
	public List<BidderChange> findBidderChanageList(String projectId) {
		StringBuffer hql = new StringBuffer("from BidderChange bc where bc.projectId=? order by bc.updateTime desc");
		return this.findAsPage(hql.toString(), null, projectId);
	}

}